//
//  Extension + UIButton.swift
//  NewMicroblog
//
//  Created by apple on 2016/10/22.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// 创建button的快捷方式
    ///
    /// - parameter setImage:        图片
    /// - parameter backgroundImage: 背景图片
    /// - parameter tagart:          tagart
    /// - parameter action:          action
    ///
    /// - returns: 
    convenience init(setImage: String, backgroundImage: String,tagart : Any?, action: Selector) {
        self.init()
        self.setImage(UIImage(named:setImage), for: .normal)
        self.setImage(UIImage(named:"\(setImage)_highlighted"), for: .highlighted)
        self.setBackgroundImage(UIImage(named:backgroundImage), for: .normal)
        self.setBackgroundImage(UIImage(named:"\(backgroundImage)_highlighted"), for: .highlighted)
        self.addTarget(tagart, action: action, for: .touchUpInside)
        self.sizeToFit()
        
    }
    
    
    convenience init(setImage: String? = nil, title: String? = nil, tagart : Any?, action: Selector) {
        self.init()
        
        if let img = setImage {
            self.setImage(UIImage(named:img), for: .normal)
            self.setImage(UIImage(named:"\(img)_highlighted"), for: .highlighted)
        }
        if let tit = title {
            self.setTitle(tit, for: .normal)
            self.setTitleColor(UIColor.darkGray, for: .normal)
            self.setTitleColor(ORANGE, for: .highlighted)
        }
        titleLabel?.font = UIFont.systemFont(ofSize: 14)
        self.addTarget(tagart, action: action, for: .touchUpInside)
        self.sizeToFit()
        
    }
    
    convenience init(backgroundImage: String,title:String,fontSzie:CGFloat,tagart : Any?, action: Selector) {
        self.init()
        self.setBackgroundImage(UIImage(named:backgroundImage), for: .normal)
        self.setBackgroundImage(UIImage(named:"\(backgroundImage)_highlighted"), for: .highlighted)
        self.addTarget(tagart, action: action, for: .touchUpInside)
        self.setTitle(title, for: .normal)
        self.titleLabel?.font = UIFont.systemFont(ofSize: fontSzie)
        self.sizeToFit()
        
    }
    
}
